package main

import (
	"geek-homework/week09/delimiter_based"
	"log"
	"net"
	"time"
)

func main() {
	conn, err := net.Dial("tcp", "127.0.0.1:8888")
	if err != nil {
		log.Fatal(err)
	}

	defer conn.Close()

	for {
		sendMessage(conn)
		sendMessage(conn)
		time.Sleep(5 * time.Second)
	}
}

func sendMessage(conn net.Conn) {
	msg := "hello world"
	buf := append([]byte(msg), delimiter_based.Delimiter)
	n, err := conn.Write(buf)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("send data [%d], %v\n", n, string(buf))
}
